<template>
	<div id="app">
		<div style="height: 20px;display:flex;align-items: center;">
			<span style="height: 20px;line-height: 20px;font-size: 20px;margin-bottom: 20px;">查看所有员工信息</span>
		</div>
		<template>
			<el-table :data="tableData" border style="width: 100%">
				<el-table-column fixed label="序号" type="index" width="50">
				</el-table-column>
				<el-table-column prop="staffId" label="员工账号" width="180">
				</el-table-column>
				<el-table-column prop="imageUrl" label="头像" width="200">
					<template slot-scope="scope" v-if="scope.row.imageUrl">
						<el-image style="width: 100px; height: 100px"
							:src="require('@/assets/staffs/'+scope.row.imageUrl)"
							:preview-src-list="[require('@/assets/staffs/'+scope.row.imageUrl)]" />
					</template>
				</el-table-column>
				<el-table-column prop="staffName" label="员工姓名" width="180">
				</el-table-column>
				<el-table-column prop="staffGender" label="员工性别" min-width="80">
				</el-table-column>
				<el-table-column prop="staffPhone" label="员工手机号" min-width="200">
				</el-table-column>
				<el-table-column prop="staffBirthdate" label="员工出生日期" width="180">
					<template slot-scope="scope" v-if="scope.row.staffBirthdate">
						<div>
							<div>{{ (scope.row.staffBirthdate).substring(0,10)}}</div>
						</div>
					</template>
				</el-table-column>
				<el-table-column prop="staffCreatetime" label="员工入职时间" min-width="180" sortable>
					<template slot-scope="scope" v-if="scope.row.staffCreatetime">
						<div>
							<div>{{ (scope.row.staffCreatetime).substring(0,10)}}</div>
						</div>
					</template>
				</el-table-column>
				<el-table-column label="操作" fixed="right">
					<template slot-scope="scope" style="display: flex;flex-direction: column;">
						<div>
							<el-button type="primary" size="mini"
								@click.prevent="handleEdit(scope.$index, scope.row)">编辑</el-button>
						</div>
						<div>
							<el-button style="margin: 0 auto;" size="mini" type="danger"
								@click="handleDelete(scope.row)">删除</el-button>
						</div>
					</template>
				</el-table-column>
			</el-table>
		</template>
	</div>
</template>

<script>
	import request from '@/utils/axios/request.js'
	export default {
		inject: ['reload'],
		data() {
			return {
				token: '',
				tableData: [{
					staffId: '',
					staffName: '',
					staffPhone: '',
					staffBirthdate: '',
					staffGender: '',
					imageUrl: '',
					staffCreatetime: ''
				}]
			}
		},
		methods: {
			handleEdit(index, row) {
				console.log(index, row);
				console.log(row.noticeId)
				this.$cookies.set("staffId", row.staffId)
				this.$router.push('/adminIndex/updateStaffs')

			},
			handleDelete(row) {
				alert('确定要删除员工编号为' + row.staffId + '的员工信息吗')
				if (window.confirm("删除流程定义的同时，相关任务也会删除，确认么？")) {
					request({
						method: 'delete',
						url: '/staffs/' + row.staffId,
					}).then(res => {
						console.log(res)
						if (res.data.code == 100) {
							alert('删除成功')
							this.reload()
						} else if (res.data.code == 101) {
							alert('删除失败，不存在该编号的员工')
						}
					})
				} else {
					return false;
				}
			}
		},
		created() {

			request({
					method: 'get',
					url: '/staffs/allStaffs',
					// headers: {
					// 	token: this.t
					// }
				})
				.then((res) => {
					console.log(res)
					var jsonObj = JSON.parse(JSON.stringify(res.data.data));
					this.tableData = jsonObj;
					// console.log(jsonObj)
				})
		}
	}
</script>

<style scoped>


</style>